package com.wangjiyuan.shiwupai.ui.fragment.guangchi;

import android.util.Log;

import com.wangjiyuan.shiwupai.bean.guangchi.categorie.CategoryBean;

import java.util.Map;

import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by wjy on 2016/11/29.
 */

public class GuangChiPresenter implements GuangChiContract.GuangChiPresenter {

    private GuangChiContract.GuangChiView mView;
    private GuangChiContract.GuangChiModel mModel;
    private Subscription subscribe;

    public GuangChiPresenter(GuangChiContract.GuangChiView view) {
        mModel = new GuangChiModel();
        mView = view;
    }

    @Override
    public void getTab(Map<String, String> map) {
        subscribe = mModel.getTab(map).observeOn(AndroidSchedulers.mainThread())
                .subscribeOn(Schedulers.io())
                .subscribe(new Subscriber<CategoryBean>() {
                    @Override
                    public void onCompleted() {
                        subscribe.unsubscribe();
                    }

                    @Override
                    public void onError(Throwable e) {
                        Log.e("asdas",e.toString());
                    }

                    @Override
                    public void onNext(CategoryBean categoryBean) {
                        mView.getTab(categoryBean.getCategories());
                    }
                });
    }
}
